package com.hl.controller.cuxiao;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.hl.domain.timeSegment;
import com.hl.domain.ActivityProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.hl.domain.SeckillActivities;
import com.hl.service.ISeckillActivitiesService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 秒杀活动Controller
 * 
 * @author vv
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/activitiess")
public class SeckillActivitiesController extends BaseController
{
    @Autowired
    private ISeckillActivitiesService seckillActivitiesService;

    /**
     * 查询秒杀活动列表
     */
    @RequiresPermissions("promotion:activitiess:list")
    @GetMapping("/list")
    public TableDataInfo list(SeckillActivities seckillActivities)
    {
        startPage();
        List<SeckillActivities> list = seckillActivitiesService.selectSeckillActivitiesList(seckillActivities);
        return getDataTable(list);
    }

    /**
     * 导出秒杀活动列表
     */
    @RequiresPermissions("promotion:activitiess:export")
    @Log(title = "秒杀活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SeckillActivities seckillActivities)
    {
        List<SeckillActivities> list = seckillActivitiesService.selectSeckillActivitiesList(seckillActivities);
        ExcelUtil<SeckillActivities> util = new ExcelUtil<SeckillActivities>(SeckillActivities.class);
        util.exportExcel(response, list, "秒杀活动数据");
    }

    /**
     * 获取秒杀活动详细信息
     */
    @RequiresPermissions("promotion:activitiess:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(seckillActivitiesService.selectSeckillActivitiesById(id));
    }

    /**
     * 新增秒杀活动
     */
    @RequiresPermissions("promotion:activitiess:add")
    @Log(title = "秒杀活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SeckillActivities seckillActivities)
    {
        return toAjax(seckillActivitiesService.insertSeckillActivities(seckillActivities));
    }

    @RequiresPermissions("promotion:activitiess:add")
    @PostMapping("/timeSegment")
    public AjaxResult insertTimeSegment(@RequestBody timeSegment timeSegment)
    {
        return toAjax(seckillActivitiesService.insertTimeSegment(timeSegment));
    }

    /**
     * 获取活动的时间段列表
     */
    @RequiresPermissions("promotion:activitiess:query")
    @GetMapping("/timeSegment/{activityId}")
    public AjaxResult getTimeSegments(@PathVariable("activityId") String activityId)
    {
        return success(seckillActivitiesService.selectTimeSegmentsByActivityId(activityId));
    }
    /**
     * 修改秒杀活动
     */
    @RequiresPermissions("promotion:activitiess:edit")
    @Log(title = "秒杀活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SeckillActivities seckillActivities)
    {
        return toAjax(seckillActivitiesService.updateSeckillActivities(seckillActivities));
    }

    /**
     * 删除秒杀活动
     */
    @RequiresPermissions("promotion:activitiess:remove")
    @Log(title = "秒杀活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(seckillActivitiesService.deleteSeckillActivitiesByIds(ids));
    }
    @DeleteMapping("/timeSegment/{id}")
    public AjaxResult deleteTimeSegment(@PathVariable String id)
    {
        return toAjax(seckillActivitiesService.deleteTimeSegment(id));
    }

    // ==================== ActivityProduct相关API ====================

    /**
     * 查询活动商品列表
     */
    @RequiresPermissions("promotion:activityProduct:list")
    @GetMapping("/activityProduct/list")
    public TableDataInfo listActivityProduct(ActivityProduct activityProduct)
    {
        startPage();
        List<ActivityProduct> list = seckillActivitiesService.selectActivityProductList(activityProduct);
        return getDataTable(list);
    }

    /**
     * 根据活动ID查询活动商品列表
     */
    @RequiresPermissions("promotion:activityProduct:list")
    @GetMapping("/activityProduct/activity/{activityId}")
    public AjaxResult getActivityProductByActivityId(@PathVariable("activityId") String activityId)
    {
        List<ActivityProduct> list = seckillActivitiesService.selectActivityProductByActivityId(activityId);
        return success(list);
    }

    /**
     * 导出活动商品列表
     */
    @RequiresPermissions("promotion:activityProduct:export")
    @Log(title = "活动商品", businessType = BusinessType.EXPORT)
    @PostMapping("/activityProduct/export")
    public void exportActivityProduct(HttpServletResponse response, ActivityProduct activityProduct)
    {
        List<ActivityProduct> list = seckillActivitiesService.selectActivityProductList(activityProduct);
        ExcelUtil<ActivityProduct> util = new ExcelUtil<ActivityProduct>(ActivityProduct.class);
        util.exportExcel(response, list, "活动商品数据");
    }

    /**
     * 获取活动商品详细信息
     */
    @RequiresPermissions("promotion:activityProduct:query")
    @GetMapping(value = "/activityProduct/{id}")
    public AjaxResult getActivityProductInfo(@PathVariable("id") String id)
    {
        return success(seckillActivitiesService.selectActivityProductById(id));
    }

    /**
     * 新增活动商品
     */
    @RequiresPermissions("promotion:activityProduct:add")
    @Log(title = "活动商品", businessType = BusinessType.INSERT)
    @PostMapping("/activityProduct")
    public AjaxResult addActivityProduct(@RequestBody ActivityProduct activityProduct)
    {
        return toAjax(seckillActivitiesService.insertActivityProduct(activityProduct));
    }

    /**
     * 修改活动商品
     */
    @RequiresPermissions("promotion:activityProduct:edit")
    @Log(title = "活动商品", businessType = BusinessType.UPDATE)
    @PutMapping("/activityProduct")
    public AjaxResult editActivityProduct(@RequestBody ActivityProduct activityProduct)
    {
        return toAjax(seckillActivitiesService.updateActivityProduct(activityProduct));
    }

    /**
     * 删除活动商品
     */
    @RequiresPermissions("promotion:activityProduct:remove")
    @Log(title = "活动商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/activityProduct/{ids}")
    public AjaxResult removeActivityProduct(@PathVariable String[] ids)
    {
        return toAjax(seckillActivitiesService.deleteActivityProductByIds(ids));
    }

    /**
     * 根据活动ID删除活动商品
     */
    @RequiresPermissions("promotion:activityProduct:remove")
    @Log(title = "活动商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/activityProduct/activity/{activityId}")
    public AjaxResult removeActivityProductByActivityId(@PathVariable String activityId)
    {
        return toAjax(seckillActivitiesService.deleteActivityProductByActivityId(activityId));
    }
}
